package com.linln.admin.system.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.linln.admin.core.enums.StatusEnum;
import com.linln.admin.core.enums.UserIsRoleEnum;

import lombok.Getter;
import lombok.Setter;

/**
 * @author 小懒虫
 * @date 2018/8/14
 */
@Entity
@Table(name = "sys_user")
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
public class User implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	private String username;
	private String password;
	private String salt;
	@JsonProperty(value = "title")
	private String nickname;
	private Long deptId;
	private String picture;
	private String sex;
	private String phone;
	private String email;
	private String remark;
	@CreatedDate
	private Date createDate;
	@LastModifiedDate
	private Date updateDate;
	private Byte isRole = UserIsRoleEnum.YES.getCode();
	private Byte status = StatusEnum.OK.getCode();

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "sys_user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
	@JsonIgnore
	private Set<Role> roles = new HashSet<>(0);

	public String getNickname() {
		return this.nickname;
	}
}
